package com.biz.extenddemo.trigger;

import com.lubase.model.DbEntity;
import com.lubase.model.DbTable;
import com.lubase.orm.exception.WarnCommonException;
import com.lubase.orm.extend.ITableTrigger;
import com.lubase.orm.util.TypeConverterUtils;
import org.springframework.stereotype.Component;

@Component
public class KaoShiTableTrigger implements ITableTrigger {

    @Override
    public Boolean beforeValidate(DbTable tableInfo, DbEntity entity, Boolean isServer) throws Exception {
        String name = TypeConverterUtils.object2String(entity.get("name"), "");
        if (name.equals("foo")) {
            throw new WarnCommonException("name is not foo");
        }
        return true;
    }

    @Override
    public Boolean isAdd() {
        return true;
    }

    @Override
    public Boolean isEdit() {
        return true;
    }

    @Override
    public String getTriggerTableCode() {
        return "xt_kaoshi";
    }

    @Override
    public String getTriggerName() {
        return "xt_kaoshi 表测试触发器";
    }
}
